
#include "main.h"
#include "SMS.h"

unsigned char Recipient_Phone[24] = "EMPTY SMS";
unsigned char *SMS_ToSend;

#define   SMS_SEND_RESULT__OK		1
#define   SMS_SEND_RESULT__FAIL	2

unsigned char SMS_Send_Result;

unsigned char SMS_Sender_Status;

near bit SMS_Start;

/* unsigned char SMS_Add_Message ( char* RecipientPhone, char* Message ) */
/* { */

/* 	if ( RecipientPhone == NULL || Message == NULL ) */
/* 	{ */
/* 		return SMS_SENDER_ERROR__DATA;  */
/* 	}   */
	
/* 	if ( SMS_Sender_Status == IDLE ) */
/* 	{ */
/* 		if ( StrLen(RecipientPhone) )	/\* use old phone number  *\/ */
/* 		{  */
/* 			StrCpy(Recipient_Phone, RecipientPhone); */
/* 		} */
/* 		else */
/* 			if ( StrLen(Recipient_Phone) == 0 ) */
/* 			{ */
/* 				return SMS_SENDER_ERROR__NO_PHONE; */
/* 			} */
		

/* 		SMS_ToSend = Message; */

/* 		putsf("\n SMS send to: ", AUX_PORT); */
/* 		puts(Recipient_Phone, AUX_PORT); */

/* 		putsf("\n SMS message: ", AUX_PORT); */
/* 		puts(SMS_ToSend, AUX_PORT); */
		
/* 		SMS_Start = TRUE; */

/* 		return 0; */
/* 	} */
	
/* 	return SMS_SENDER_ERROR__SENDER_BUSY;   */
/* } */

/* int SMS_Sender ( int Result ) */
/* { */
/* 	static unsigned int State = ST_START, NextState, NextStateIfError; */

/* 	SMS_Sender_Status = State; */

/* 	switch( State ) */
/* 	{ */
/* 		case ST_START: */
/* 				Debug("\n == SMS Sender started == ", 1); */

/* 		case ST_RESET: */
/* 				State = IDLE; */
/* 				break; */

/* 		case IDLE: */
/* 			if ( SMS_Start ) */
/* 			{ */
				
/* 			} */

/* 			if ( Fifo_Entry_Read(&SMS_Fifo, s) != 0 ) */
/* 			{ */
/* 				DBG_OUT("\n SMS. Fifo_Entry_Read: %s", s); */
/* 				StrCpy(SMS_Send_Buffer, AT_SMS_SEND); */
/* 				StrCat(SMS_Send_Buffer,"\""); */
/* 				StrCpy_UpTo_Ch(&SMS_Send_Buffer[StrLen(SMS_Send_Buffer)] , s, ';'); */
/* 				StrCat(SMS_Send_Buffer,"\"\r##"); */

/* 				/\* Calculate Password *\/ */
/* 				//StrCpy_UpTo_Ch(Phone, s, ';'); */

/* 				//PasswordCalculator(&SMS_Send_Buffer[StrLen(SMS_Send_Buffer)], Phone); */
/* 				StrCpy(&SMS_Send_Buffer[StrLen(SMS_Send_Buffer)], SMS_Password); */

/* 				//Phone[0] = RANDOM(4,255); /\* Message Label *\/ */
/* 				//HexToChar((unsigned char*)&SMS_Send_Buffer[StrLen(SMS_Send_Buffer)], (unsigned char*)Phone, 1); */
/* 				//StrCat(SMS_Send_Buffer, "0101"); */
/* 				StrCat(SMS_Send_Buffer, IMEI); */
/* 				StrCat(SMS_Send_Buffer, StrPointerOfChar(s, ';', 1)); */
/* 				StrCat(SMS_Send_Buffer,"$\x1A"); */
/* 				DBG_OUT("\n SMS_Send_Buffer: %s\n", SMS_Send_Buffer); */
/* 				State = SMS_SEND; */
/* 			} */
/* 			break; */

/* 		case SMS_SEND: */
/* 			if ( Modem_Send(NULL, NULL, NULL, SMS_Send_Buffer, NULL) != -1 ) */
/* 			{ */
/* 				State = CHECK_FOR_RESULT; */
/* 				NextState = IDLE; */
/* 				NextStateIfError = SMS_SEND; */
/* 			} */
/* 			else */
/* 			{ */
/* 				OS_Sleep(1000); */
/* 			} */
/* 			break; */

/* 		case CHECK_FOR_RESULT: */
/* 			if ( Result == SUCCESSFUL ) */
/* 			{ */
/* 				DBG_OUT("\n SMS Sender: SUCCESSFUL\n"); */
/* 				State = NextState; */
/* 			} */
/* 			else */
/* 			{ */
/* 				DBG_OUT("\n SMS Sender: FAIL\n"); */
/* 				OS_Sleep(5000); */
/* 				State = NextStateIfError; */
/* 			} */
/* 			break; */

/* 		case ST_TIMEOUT: */
/* 			Result = FAIL; */

/* 		case ST_EXIT: */
/* 			State = ST_RESET; */
/* 			break; */

/* 		default: */
/* 			; */
/* 	} */
	
/* 	return Result; */
/* } */
















 
/* /\* Return how many items in the list and fill SMS_List with numbers of received SMS messages*\/ */
/* unsigned char SMS_Get_List( const unsigned char* SMS_READ_UNREAD, unsigned char* SMS_List  ) */
/* { */
/* 	static unsigned char State = 0, i; */
/* //	unsigned char s[4]; */
	
/* 	switch ( State ) */
/* 	{ */
/* 		case 0:						  /\* Get messages list  *\/ */
/* 			if ( ModemStatus == READY ) */
/* 			{ */
/* //				MODEM_STATE = TO_WAKES; */
/* //				delay_ms(35); */
/* 				ModemStatus = BUSY_SMS_GET_LIST; */
/* 				i = 0; */
/* 				State++; */
/* 			} */
/* 			break; */

/* 		case 1: */
/* 			//putsf(AT__GET_SMS_READ, MODEM_PORT); */
/* 			putsf( SMS_READ_UNREAD, MODEM_PORT ); */
/* 			SMS_List[0] = 0; */
/* 			State++; */
/* 			break; */

/* 		case 2: */
/* 			if ( ModemEvents == MODEM_NEW_MESSAGE_PART ) */
/* 			{ */
/* 				if ( !StrCmp("+CMGL", ModemRecBuffer) || errno == 5 ) */
/* 				{ */
/* 					SMS_List[i++] = StrToLong(ModemRecBuffer); */
					
/* 					//putsf("\rM:", AUX_PORT); */
/* 					//puts(LongToStr(s,SMS_List[i-1]), AUX_PORT); */
					
/* 				} */
/* 			} */
/* 			else */
/* 				if ( ModemEvents == MODEM_NEW_MESSAGE_COMPLETE ) /\* Receive MODEM__OK *\/ */
/* 				{ */
/* 					SMS_List[i] = 0;	  /\* end of SMS List *\/ */
/* 					ModemStatus = READY; */
/* 					State = 0; */
/* 					//putsf("\rEndOfList", AUX_PORT); */
/* 					return i; */
/* 				} */
/* 				else */
/* 					if ( ModemEvents == MODEM_ERROR ) */
/* 					{ */
/* 						ModemStatus = READY; */
/* 						State = 0; */
/* 						return MODEM_ERROR; */
/* 					} */

/* 			break; */

/* 		default: */
/* 			; */
/* 	} */

/* 	return BUSY; */
/* } */
